<div id="page_profil">
<fly:include name="tabs" />
<h1><fly:block name="add">Add more account</fly:block><fly:block name="create">Create account</fly:block></h1>
    <p>
        <strong>Attention</strong> : une fois que vous aurez choisi votre pseudo vous ne pourrez plus le modifier par la suite. <br />
		Le choix de votre pseudo est soumis à une validation, prenez soin de choisir un pseudo convenable.
    </p>
    <form method="post" name="formulaire" onSubmit="return registerSubmit()">
    <input type="hidden" name="birth_date_ok" id="birth_date_ok" value="<fly:variable name='birth_date_ok'/>" size="8" />
        <fieldset>
			<div id="form-ligne">
				<div id="form-titre"><label for="pseudo">Pseudo/login *</label></div>
				<div id="form-field">								
	                    <input alt="Pseudo" AUTOCOMPLETE=OFF  class="username validated oblig" type="text" name="pseudo" id="pseudo" size="25" maxlength="255" onkeypress="return keyEnable(event,'textnumber')" /><div id="pseudo_img"></div><div id="pseudo_msg"></div>
        		</div>
        	</div>
			<div id="form-ligne">
				<div id="form-titre"><label for="password">Password *</label></div>
				<div id="form-field">								
	                    <input alt="Password" AUTOCOMPLETE=OFF  class="pwd validated oblig" type="password" name="password" id="password" size="25" maxlength="255" /><div id="password_img"></div><div id="password_msg"></div>
        		</div>
        	</div>
			<div id="form-ligne">
				<div id="form-titre"><label for="repeat_pasword">Repeat password *</label></div>
				<div id="form-field">								
	                    <input alt="Repeat pasword" AUTOCOMPLETE=OFF  class="validated oblig" type="password" name="repeat_pasword" id="repeat_pasword" size="25" maxlength="255" /><div id="repeat_pasword_img"></div><div id="repeat_pasword_msg"></div>
        		</div>
        	</div>
        	<div id="form-ligne">
				<div id="form-titre"><label for="birth_date">Birth date *</label></div>
				<div id="form-field">								
	                    <input  alt="Birth date" class="calendar oblig" type="text" name="birth_date" id="birth_date" size="25" maxlength="255" /><div id="birth_date_img"></div><div id="birth_date_msg"></div>
        		</div>
        	</div>
        	<div id="form-ligne">
				<div id="form-titre"><label for="language_default">Language default *</label></div>
				<div id="form-field">								
	                <select name="language_default" id="language_default" class="mandatory validated">
					<fly:list name="list-language">
						<option <fly:variable name="selected"/> value="<fly:variable name='id_language' />">
							<fly:variable name="language" />
						</option>
					</fly:list>
					</select>
							<div id="lang_default_img"></div><div id="lang_default_msg"></div>							
        		</div>
        	</div>
        	<div id="form-ligne">
				<div id="form-titre">&nbsp;</div>
				<div id="form-field">								
	                <input type="submit" name="submit" value="<fly:block name="add">Add</fly:block><fly:block name="create">Create</fly:block>" class="submit" />							
        		</div>
        	</div>
        	
      
        </fieldset>
    </form>
</div>
<script type="text/javascript">
var delay_search = <fly:variable name="delay_search" />;
var timeout=null;
var validated=true;
var completed=false;
function complete(){
	var type;
	if($('#birth_date').val()=='') { $('#birth_date').focus(); return false;}
	$('.img_info').each(function(){		
		file = $(this).attr('src');		
		type =  file.substring(file.lastIndexOf('/')+1,file.indexOf('.'));		
		if(type=='exclamation') return false;
	});
	//alert(type);
	if(type == 'exclamation')return false; else return true;	
}
function validateForm(){//must addscript date_validate.js
	var dt=$('#birth_date');//frmSample and birth_day is alway change so we put here
	if (isDateInscript(dt.val())==false){
		//dt.focus();
		//alert('not date'+validated);
		return validated=false;
	}else{
	   	$.get('<fly:variable name="rep_ajax"/>inscription/check_old.php',{birth_date: dt.val()},function(data){	   			   		    	
	   			   		//alert('good date'+data);
	   		//insert birth day to birth_date_ok textbox
	   		maReg = new RegExp("#(.+)#");
			ret = maReg.exec(data);
			birth_day = ret[0].substr(1, ret[0].length-2);			
		   	$('#birth_date_ok').val(birth_day);
	   	});
	   	if($('#pseudo').val()!= '')	{
	   		$.fn.validate.username($('#pseudo'));
	   	}else{
	   		//alert('no pseudo'+validated);
	   		return validated=false;
	   	}   		
   	}
   		
}
//private helper, validates each type after check
 function doValidate(o) {
		if (timeout) clearTimeout(timeout);
		timeout = setTimeout(function(){
	    	$('#' + o.id + '_img').html('<img src="_design/loading.gif" border="0" style="float:left;" />');
	    	$.post('<fly:variable name="rep_ajax"/>inscription/eval_info.php',{ field: $(o).attr('id'), value: $(o).val() },function(data){    	
	    		if (data == 'true')
		       	{
		       		//alert('good pseudo'+validated);
		       	  $(o).validate.doSuccess(o);
		       	  return validated=true;
		       	}
		       	else
		       	{//alert('false');
		       	//alert('not good pseudo'+validated);
	              $(o).validate.doError(o,$(o).attr('alt')+data);
	              return validated=false;
		       	}
	    	});
		}, delay_search);	
	
};
function registerSubmit(){
	completed = complete();
	
	//alert(validated+' = '+completed);
	if(validated==true && completed==true){			
		return true;
	} else return false;
}
$(document).ready(function(){
	
	$('#birth_date').change(function(){
		validateForm();		
	});
	
	$("#repeat_pasword").keyup(function() {  			
          $(this).match($('#password'),$("#repeat_pasword"));
  	});
  	$("#repeat_pasword").blur(function() {  			
          $(this).match($('#password'),$("#repeat_pasword"));
  	});
	$('.calendar').calendarInscription({autoPopUp: 'both', 

	buttonImageOnly: true, buttonImage: '../_design/calendar.gif', 

	buttonText: 'Calendar'});
});
</script>